package com.example.lin.qq_home_project.activity;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.example.lin.qq_home_project.R;
import com.example.lin.qq_home_project.adapter.SuiPianPagerAdapter;
import com.example.lin.qq_home_project.fragment.ContactFragment;
import com.example.lin.qq_home_project.fragment.ConversationFragment;
import com.example.lin.qq_home_project.fragment.NowFragment;
import com.example.lin.qq_home_project.fragment.PluginFragment;

public class WeChatHomeActivity extends AppCompatActivity {

    private ViewPager vp_container;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_we_chat_home);

        initView();
    }

    private void initView() {
        vp_container = findViewById(R.id.vp_container);

        Fragment[] fragments ={new ConversationFragment(),new ContactFragment(),new NowFragment(),new PluginFragment()};

        MyFragmentPagerAdapter myFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager(), fragments);
        //FragmentPagerAdapter
        vp_container.setAdapter(myFragmentPagerAdapter);
    }

    class MyFragmentPagerAdapter extends FragmentPagerAdapter {

        private Fragment[] fragments;

        public MyFragmentPagerAdapter(FragmentManager fm, Fragment[] fragments) {
            super(fm);
            this.fragments = fragments;
        }

        @Override
        public Fragment getItem(int position) {
            return fragments[position];
        }

        @Override
        public int getCount() {
            return fragments == null ? 0 : fragments.length;
        }
    }


}
